import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.Date;


public class UDPFileServer {

	public static void main1(String[] args) throws IOException {
		DatagramSocket server = new DatagramSocket(1234);
		byte[] buffer = new byte[255];
		DatagramPacket in = new DatagramPacket(buffer, buffer.length);
		server.receive(in);
		System.out.println(Arrays.toString(buffer));
		DatagramPacket out = new DatagramPacket(buffer, buffer.length,in.getSocketAddress());
		server.send(out);
	}
	
	public static void main(String[] args) throws IOException, InterruptedException {
		DatagramSocket sender = new DatagramSocket();
		while(true) {
			String message = "From Ivo " + new Date().toString();
			byte[] buffer = message.getBytes();
			DatagramPacket out = new DatagramPacket(buffer, buffer.length, InetAddress.getByName("255.255.255.255"), 4444);
			sender.send(out);
			Thread.sleep(1000);
		}
	}
}
